import threading
import numpy as np
from predictAllDict import predict_all_dict


class myThread():
    def __init__(self):
        self.all_data = np.zeros((25, 45, 5))
        self.path = './bock_count_json'  # json文件夹路径
        self.length = 25  # 格子行
        self.width = 45  # 格子列

        self.th_list = []

    def run(self):
        for i in range(5):
            self.th_list.append(threading.Thread(target=self.fun, args=(i,)))

        for item in self.th_list:
            item.start()

    def fun(self, i):
        result = predict_all_dict(self.path, self.length, self.width)
        self.all_data[i] = result

        with open('ans.txt', 'w') as outfile:
            for slice_2d in test.all_data:
                np.savetxt(outfile, slice_2d, fmt='%f', delimiter=',')

        print('finish-- ', i)


if __name__ == '__main__':
    test = myThread()
    test.run()
    print('finish')

